package com.example.spinning.service;

import com.example.spinning.bean.SpinningSummary;
import com.example.spinning.mapper.SpinningSummaryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpinningSummaryService {

    @Autowired
    private SpinningSummaryMapper spinningSummaryMapper;

    //得到投料单信息
    //带有分页功能的展现数据
    public List<SpinningSummary> getAllSpinningSummary(Integer page, Integer count) {
        int start = (page - 1) * count;
        return spinningSummaryMapper.getSpinningSummary(start,count);
    }

    //找到行数
    public int getSpinningSummaryCount() {
        return spinningSummaryMapper.getCountSpinningSummary();
    }

    //根据条件找到行数
        public int getSpinningSummaryCountByCondition(String customer, String workshop, String date, String batch_no, String num, String composition){
        return spinningSummaryMapper.getCountSpinningSummaryByCondition(customer,workshop,date,batch_no,num,composition);
    }

    //根据id查询投料单信息
    public SpinningSummary getSpinningSummaryById(long id){
        SpinningSummary order = spinningSummaryMapper.getSpinningSummaryById(id);
        return order;
    }

    //根据条件模糊查询
    public List<SpinningSummary> getSpinningSummaryByCondition(Integer page, Integer count, String customer, String workshop, String date, String batch_no, String num, String composition){
        int start = (page - 1) * count;
        return spinningSummaryMapper.getSpinningSummaryByCondition(start,count,customer,workshop,date,batch_no,num,composition);
    }

    //添加投料单信息
    public int addSpinningSummary(SpinningSummary order){
        return spinningSummaryMapper.addSpinningSummary(order);
    }


    //修改
    public int updateSpinningSummary(SpinningSummary order){
        return spinningSummaryMapper.updateSpinningSummaryById(order);
    }

    //删除
    public boolean deleteSpinningSummaryByIds(String ids){
        String[] split = ids.split(",");
        int result = spinningSummaryMapper.delSpinningSummaryById(split);
        return result == split.length;
    }


}
